import { parse, stringify } from 'csv'

// string转json
export function parseFromCSV(text: any): Promise<any[]> {
  return new Promise(function (resolve, reject) {
    parse(text, function (err: any, data: any) {
      if (err) return reject(err)
      return resolve(data)
    })
  })
}

// json转string
export function stringifyToCSV(list: any): Promise<string> {
  return new Promise(function (resolve, reject) {
    stringify(list, function (err, data) {
      if (err) return reject(err)
      return resolve(data)
    })
  })
}
